package group.raber.jeki.controller

import group.raber.saber.kit.MapKit
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.servlet.ModelAndView

@Controller
class IndexController {

    @RequestMapping("/")
    ModelAndView index() {
        Map<String,Object> vars = new HashMap<String,Object>();

        return new ModelAndView("views/index",vars);
    }
    @RequestMapping("/domain/{domainCode}")
    ModelAndView domain(@PathVariable("domainCode") String domainCode) {
        Map<String,Object> vars = new HashMap<String,Object>();

        return new ModelAndView("views/domain",vars);
    }
    @RequestMapping("/tag/{tag}")
    ModelAndView tag(@PathVariable("tag") String tag) {
        Map<String,Object> vars = new HashMap<String,Object>();

        return new ModelAndView("views/tag",vars);
    }

    @RequestMapping("/register")
    ModelAndView register() {
        new ModelAndView("views/register",[:]);
    }

    @RequestMapping("/logon")
    ModelAndView logon() {
        new ModelAndView("views/logon",MapKit.newHashMap());
    }
    @RequestMapping("/logoff")
    ModelAndView logoff() {
        return index();
    }
    @RequestMapping("/logonAction")
    ModelAndView logonAction() {
        new ModelAndView("views/logon",[:]);
    }
    @RequestMapping("/article/{articleId}")
    ModelAndView article() {
        new ModelAndView("views/article",[:]);
    }

    @RequestMapping("/article-create")
    ModelAndView createArticle() {
        new ModelAndView("views/article-editor",[:]);
    }
    @RequestMapping("/article-editor")
    ModelAndView editArticle(@PathVariable("articleId") String articleId) {
        new ModelAndView("views/article-editor",[:]);
    }
    @RequestMapping("/redirector/{uri:.+}")
    ModelAndView redirector(@PathVariable("uri") String uri) {
        System.out.println("URI:"+uri);
        new ModelAndView("views/index",[:]);
    }
}
